package com.mvp.shq.washer.ui.shop.shopAddAddress;

import com.mvp.shq.washer.entity.result.BaseResult;
import com.mvp.shq.washer.entity.shop.AddressData;
import com.mvp.shq.washer.http.BaseObserver;
import com.mvp.shq.washer.utils.SpUtil;
import com.mvp.shq.washer.utils.T;

/**
 * Created by Administrator on 2017/10/10.
 */

public class Presenter extends ShopAddAddressConstract.Presenter {
    @Override
    public void onStart() {

    }

    @Override
    void addOrUpdateAddress(AddressData address) {
        String token = SpUtil.getToken();
        String userId = SpUtil.getUser().getId();
        model.addOrUpdateAddress(token,userId,address.getId(),address.getReceiverPhone(),address.getReceiverName(),address.getProvinceId(),
                address.getProvinceName(),address.getCityId(),address.getCityName(),address.getAreaId(),address.getAreaName(),
                address.getUnitId(),address.getUnitName(),address.getDetailAddress(),address.getStatus()
        )
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .subscribe(new BaseObserver<String>(view) {
                    @Override
                    protected void onSuccees(BaseResult<String> t) throws Exception {
                        if (t.isError()){
                            T.show(t.getMsg());
                        }else {
                            view.addOrUpdateAddressS();
                        }
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        T.show(e.getMessage());
                        e.printStackTrace();
                    }
                });
    }
}
